#!/bin/bash

## @Version	1.0
## @Author	Fabio Grucci (alias Phoenix)
## @License	LGPL


##########################
##### ARRAYS PACKAGE #####
######### V 1.0 ##########
##########################

./ifndef.sh ./functions.sh;
./ifndef.sh ./booleans.sh;

#. ./functions.sh;			# ALSO USE RETURN_VALUE METHOD

#. ./booleans.sh;			# FOR TRUE FALSE VARIABLE

declare -a PARAMETERS;

## Revert script parameters in to an array named PARAMETERS
function parametersToArray() {
	index=0;
	for parameter in "$@"; do
		PARAMETERS[index++]=$parameter;
	done;
	setLastReturnValue "PARAMETERS[*]";
}

function valueContains() {
	VALUE_TO_SEARCH="$1";
	declare -i I;	#index of iteration
	for (( I=1; I<${#PARAMETERS[*]}; I++ )); do;
		declare -r ELEMENT="${PARAMETERS[$I]}";
		if [ "$ELEMENT" -eq  ]; then
			setLastReturnValue "$TRUE";
			break;
		fi;
	done;
	echo -e '#\t\t'	'\t'	'echo "elemento[$I]: ";';
	echo -e '#\t\t'		'done
}

##########################
### END ARRAYS PACKAGE ###
##########################


##########################
#### BASH ARRAYS HELP ####
##########################

function printDefinitionType() {
	echo -e '## Definition Type';
	echo -e '#\tdefinition type 1: ARY=( one two three four )';
	echo -e '#\tdefinition type 2: declare -a ARY=( one two three four )';
}

function printCommonsArraysFunctions() {
	declare -a -r ARY=( one two three four );
	echo -e '## Function of array with example con array like: ARY=( one two three four )';
	echo -e '#\tget number of elements of an array:\t'	'"${#ARY[*]}"'	'\t'	'\t-->\t'	"${#ARY[*]}";
	echo -e '#\tget the second element of an array:\t'	'"${ARY[1]}"'	'\t'	'\t-->\t'	"${ARY[1]}";
	echo -e '#\tget the two elements after the third:\t'	'"${ARY[@]:3:2}"'		'\t-->\t'	"${ARY[@]:3:2}";
	echo -e '#\tget all the array:\t'	'\t'	'\t'	'"${ARY[*]}"'	'\t'	'\t-->\t'	"${ARY[*]}";
}

function printCommonsUsageMethod() {
	echo -e '## Commons usage Method';
	echo -e "#\t loop of printing on array's elements:";
	echo -e '#\t\t'		'for (( I=0; I<${#ARY[*]}; I++ )); do';
	echo -e '#\t\t'	'\t'	'echo "elemento[$I]: ${ARY[$I]}";';
	echo -e '#\t\t'		'done;';
}

function printArrayHelp() {
	printDefinitionType;
	echo "#";
	printCommonsArraysFunctions;
	echo "#";
	printCommonsUsageMethod;
}

##########################
## END BASH ARRAYS HELP ##
##########################